<?php 
/**
*	file: ProcessIntake1.php
*	path: /webroot/actions/
*	notes:   
*		this form was updated with VAIL customization on 10-16-08.
*		several new drop down field options were added.
*		
*/

	//FOR DEBUGGING--comment out when done!
	ini_set('display_errors', 1);
	ini_set('error_reporting', E_ALL ^ E_NOTICE);
	error_reporting(1);

	session_start();
	
	include('../includes/db_connect.php'); 
	//include('../includes/phpheader.php');

	$id = $_POST["id"];

	$vote = $_POST["vote"];

	$otherName = $_POST["otherName"];
	$otherPhone = $_POST["otherPhone"];
	$otherLanguage = $_POST["otherLanguage"];
	$otherOtherLanguage = $_POST["otherOtherLanguage"];
	$otherLiving = $_POST["otherLiving"];

	$dateMonth = $_POST["dateMonth"];
	$dateDay = $_POST["dateDay"];
	$dateYear = $_POST["dateYear"];
	$date = $dateYear."-".$dateMonth."-".$dateDay; 

	$birthDateMonth = $_POST["birthDateMonth"];
	$birthDateDay = $_POST["birthDateDay"];
	$birthDateYear = $_POST["birthDateYear"];
	$birthDate = $birthDateYear."-".$birthDateMonth."-".$birthDateDay;

	$age = $_POST["age"];
	if(!$age) {
		$age=0;
	}

	$sex = $_POST["sex"];
	$race = $_POST["race"];
	$maritalStatus = $_POST["maritalStatus"];
	$dependents = $_POST["dependents"];

	if(strcmp($dependents,"0") == 0)
		$dependentsHowMany = 0;
	else
		$dependentsHowMany = $_POST["dependentsHowMany"];
	
	$birthplaceCity = $_POST["birthplaceCity"];
	$birthplaceState = $_POST["birthplaceState"];
	$citizen = $_POST["citizen"];

	$ethnicity = $_POST["ethnicity"];
	$primaryDisability = $_POST["primaryDisability"];
	$secondaryDisability = $_POST["secondaryDisability"];
	$primaryDisabilityType = $_POST["primaryDisabilityType"];
	$secondaryDisabilityType = $_POST["secondaryDisabilityType"];
	$congenital = $_POST["congenital"];
	$traumatic = $_POST["traumaticInjury"];
	$disease = $_POST["disease"];

	$servicesDARS = $_POST["servicesDARS"];
	$servicesTCB = $_POST["servicesTCB"];
	$servicesMHMR = $_POST["servicesMHMR"];	
	$servicesDHS = $_POST["servicesDHS"];
	$servicesSchool = $_POST["servicesSchool"];
	$servicesSSA = $_POST["servicesSSA"];	
	$servicesHAHA = $_POST["servicesHAHA"];
	$servicesTAN = $_POST["servicesTAN"];
	$servicesOther = $_POST["servicesOther"];
	
	$counselorName = $_POST["counselorName"];
	$counselorNumber = $_POST["counselorNumber"];

	$incomeJobs = $_POST["incomeJobs"];
	$incomeSS = $_POST["incomeSS"];
	$incomeSSI = $_POST["incomeSSI"];
	$incomeSSDI = $_POST["incomeSSDI"];
	$incomePublicAssistance = $_POST["incomePublicAssistance"];
	$incomeClinicCard = $_POST["incomeClinicCard"];
	$incomeWorkmansCompensation = $_POST["incomeWorkmansCompensation"];
	$incomePension = $_POST["incomePension"];
	$incomeMedicare = $_POST["incomeMedicare"];
	$incomeMedicaid = $_POST["incomeMedicaid"];
	$incomeUnemploymentBenefits = $_POST["incomeUnemploymentBenefits"];
	$incomePrivateHealthInsurance = $_POST["incomePrivateHealthInsurance"];
	
	$transportationOption = $_POST["transportationOption"];
	//$transportationOption = 3;
	$referralName = $_POST["referralName"];
	$referralOther = $_POST["referralOther"];
	$capSignoff = $_POST["capSignoff"];
	$waiverILP = $_POST["waiverILP"];

	if(!$congenital)	$congenital=0; 	else 	$congenital=1;
	if(!$traumatic) 	$traumatic=0; 	else 	$traumatic=1;
	if(!$disease) 		$disease=0; 		else 	$disease=1;

	if(!$servicesDARS)		$servicesDARS=0; 		else 	$servicesDARS=1;
	if(!$servicesTCB)			$servicesTCB=0; 		else 	$servicesTCB=1;
	if(!$servicesMHMR)		$servicesMHMR=0; 		else 	$servicesMHMR=1;
	if(!$servicesDHS)			$servicesDHS=0; 		else 	$servicesDHS=1;
	if(!$servicesSchool)	$servicesSchool=0; 	else 	$servicesSchool=1;
	if(!$servicesSSA)			$servicesSSA=0; 		else 	$servicesSSA=1;
	if(!$servicesHAHA)		$servicesHAHA=0; 		else 	$servicesHAHA=1;
	if(!$servicesTAN)			$servicesTAN=0; 		else 	$servicesTAN=1;
	if(!$servicesOther)		$servicesOther=0; 	else 	$servicesOther=1;

	if(!$incomeJobs)	$incomeJobs=0; 		else 	$incomeJobs=1;
	if(!$incomeSS)	$incomeSS=0; 		else 	$incomeSS=1;
	if(!$incomeSSI)	$incomeSSI=0; 		else 	$incomeSSI=1;
	if(!$incomeSSDI)	$incomeSSDI=0; 		else 	$incomeSSDI=1;
	if(!$incomePublicAssistance)  $incomePublicAssistance=0; 		else 	$incomePublicAssistance=1;
	if(!$incomeClinicCard)	$incomeClinicCard=0; 		else 	$incomeClinicCard=1;
	if(!$incomeWorkmansCompensation) $incomeWorkmansCompensation=0; 		else 	$incomeWorkmansCompensation=1;
	if(!$incomePension)	$incomePension=0; 		else 	$incomePension=1;
	if(!$incomeMedicare)	$incomeMedicare=0; 		else 	$incomeMedicare=1;
	if(!$incomeMedicaid)		$incomeMedicaid=0; 		else 	$incomeMedicaid=1;
	if(!$incomeUnemploymentBenefits)	$incomeUnemploymentBenefits=0; 		else 	$incomeUnemploymentBenefits=1;
	if(!$incomePrivateHealthInsurance)	$incomePrivateHealthInsurance=0; 		else 	$incomePrivateHealthInsurance=1;

	if(!$capSignoff)	$capSignoff=0; 		else 	$capSignoff=1;

	$employeeSignature = $_POST["employeeSignature"];
	$consumerSiganture = $_POST["consumerSiganture"];

	$eligibilitySignoff = $_POST["eligibilitySignoff"];
	if(!$eligibilitySignoff) 	$eligibilitySignoff=0;  else 	$eligibilitySignoff=1;

	####################################################################
	#	NEW VAIL DATA ELEMENTS
	
##	VAIL PROGRAMS
	if(!$vailProgram1) $vailProgram1=0; 	else	$vailProgram1 = $_POST["vailProgram1"];
	if(!$vailProgram2) $vailProgram2=0; 	else	$vailProgram2 = $_POST["vailProgram2"];
	if(!$vailProgram3) $vailProgram3=0; 	else	$vailProgram3 = $_POST["vailProgram3"];
	if(!$vailPreviousProgram1) $vailPreviousProgram1=0; 	else	$vailPreviousProgram1 = $_POST["vailPreviousProgram1"];
	if(!$vailPreviousProgram2) $vailPreviousProgram2=0; 	else	$vailPreviousProgram2 = $_POST["vailPreviousProgram2"];
	/*
	echo"<h1>".	$vailProgram1 ."</h1>";
	echo"<h1>".	$vailProgram2 ."</h1>";
	echo"<h1>".	$vailProgram3 ."</h1>";
	echo"<h1>".	$vailPreviousProgram1 ."</h1>";
	echo"<h1>".	$vailPreviousProgram2 ."</h1>";
	die();
	*/

## STATE PROGRAMS
	if(!$stateProgram1)$stateProgram1 =0; 	else 	$stateProgram1 = $_POST["stateProgram1"];
	if(!$stateProgram2)$stateProgram2 =0; 	else 	$stateProgram2 = $_POST["stateProgram2"];
	if(!$stateProgram3)$stateProgram3 =0; 	else 	$stateProgram3 = $_POST["stateProgram3"];
	if(!$statePreviousProgram1)$statePreviousProgram1 =0; 		else 	$statePreviousProgram1 = $_POST["statePreviousProgram1"];
	if(!$statePreviousProgram2)$statePreviousProgram2 =0; 		else 	$statePreviousProgram2 = $_POST["statePreviousProgram2"];

## INCOME SOURCES
	if(!$incomeSource1) $incomeSource1=0; 	else 	$incomeSource1 = $_POST["incomeSource1"];
	if(!$incomeSource2) $incomeSource2=0; 	else 	$incomeSource2 = $_POST["incomeSource2"];
	if(!$incomeSource3) $incomeSource3=0; 	else 	$incomeSource3 = $_POST["incomeSource3"];
	if(!$incomeSource4) $incomeSource4=0; 	else 	$incomeSource4 = $_POST["incomeSource4"];
	if(!$incomeSource5) $incomeSource5=0; 	else 	$incomeSource5 = $_POST["incomeSource5"];

## ADDITIONAL ASSISTANCE
	if(!$additionalAssistance1)$additionalAssistance1=0; 	else	$additionalAssistance1 = $_POST["additionalAssistance1"];
	if(!$additionalAssistance2)$additionalAssistance2=0; 	else	$additionalAssistance2 = $_POST["additionalAssistance2"];
	if(!$additionalAssistance3)$additionalAssistance3=0; 	else	$additionalAssistance3 = $_POST["additionalAssistance3"];
	if(!$additionalAssistance4)$additionalAssistance4=0; 	else	$additionalAssistance4 = $_POST["additionalAssistance4"];
	if(!$additionalAssistance5)$additionalAssistance5=0; 	else	$additionalAssistance5 = $_POST["additionalAssistance5"];

## REFERRALS
	if(!$referredTo1)$referredTo1=0;	else	$referredTo1 = $_POST["referredTo1"];
	if(!$referredTo2)$referredTo2=0;	else	$referredTo2 = $_POST["referredTo2"];
	if(!$referredFrom1)$referredFrom1=0;	else	$referredFrom1 = $_POST["referredFrom1"];
	if(!$referredFrom2)$referredFrom2=0;	else	$referredFrom2 = $_POST["referredFrom2"];
	
	####################################################################

	$query = "SELECT id 
		     FROM intake1 
		    WHERE consumer_id = ".$id;

if(mysql_fetch_array(mysql_query($query))) {

	$query = "UPDATE intake1 
				SET voting = ".$vote.",
					date = '".$date."',
					other_contact='".$otherName."', 
					other_contact_phone ='".$otherPhone."', 
					other_language_needs = '".$otherLanguage."', 
					other_other_language_needs = '".$otherOtherLanguage."', 
					living_arrangement_id = ".$otherLiving.", 
					age = ".$age.", 
					sex_id = ".$sex.", 
					race_id = ".$race.", 
					marital_status_id = ".$maritalStatus.", 
					dependents = ".$dependents.", 
					dependents_count = ".$dependentsHowMany.", 
					birth_city = '".$birthplaceCity."', 
					birth_state_id = '".$birthplaceState."', 
					citizen = ".$citizen.", 
					dob ='".$birthDate."', 
					ethnicity = '".$ethnicity."', 
					primary_disability_id = ".$primaryDisability.", 
					secondary_disability_id = '".$secondaryDisability."', 
					primary_disability_type_id = ".$primaryDisabilityType.", 
					secondary_disability_type_id = '".$secondaryDisabilityType."', 
					congenital = ".$congenital.", 
					traumatic = ".$traumatic.", 
					disease = ".$disease.", 
					employee_signature = '".$employeeSignature."', 
					eligibility_signoff = '".$eligibilitySignoff."', 
					consumer_signature = '".$consumerSiganture."', 
					services_DARS = ".$servicesDARS.", 
					services_TCB = ".$servicesTCB.", 
					services_MHMR = ".$servicesMHMR.", 
					services_DHS = ".$servicesDHS.", 
					services_School = ".$servicesSchool.", 
					services_SSA = ".$servicesSSA.", 
					services_HAHA = ".$servicesHAHA.", 
					services_TAN = ".$servicesTAN.", 
					services_Other = ".$servicesOther.", 
					counselor_name = '".$counselorName."', 
					counselor_number = '".$counselorNumber."', 
					income_Jobs = ".$incomeJobs.", 
					income_SS = ".$incomeSS.", 
					income_SSI = ".$incomeSSI.", 
					income_SSDI = ".$incomeSSDI.", 
					income_public_assistance = ".$incomePublicAssistance.", 
					income_clinic_card = ".$incomeClinicCard.", 
					income_workmans_compensation = ".$incomeWorkmansCompensation.", 
					income_pension = ".$incomePension.", 
					income_medicare = ".$incomeMedicare.", 
					income_medicaid = ".$incomeMedicaid.", 
					income_unemployment_benefits = ".$incomeUnemploymentBenefits.", 
					income_private_health_insurance = ".$incomePrivateHealthInsurance.", 
					transportation_option_id = ".$transportationOption.", 
					referral_name = '".$referralName."', 
					referral_other = '".$referralOther."', 
					cap_signoff=".$capSignoff.", 
					waiverILP = ".$waiverILP.",
					program_enrolled1=".$vailProgram1.",
					program_enrolled2=".$vailProgram2.",
					program_enrolled3=".$vailProgram3.",
					program_previous_enrolled1=".$vailPreviousProgram1.",
					program_previous_enrolled2=".$vailPreviousProgram2.",
					state_program_enrolled1=".$stateProgram1.",
					state_program_enrolled2=".$stateProgram2.",
					state_program_enrolled3=".$stateProgram3.",
					state_program_previous_enrolled1=".$statePreviousProgram1.",
					state_program_previous_enrolled2=".$statePreviousProgram1.",
					income_source1=".$incomeSource1.",
					income_source2=".$incomeSource2.",
					income_source3=".$incomeSource3.",
					income_source4=".$incomeSource4.",
					income_source5=".$incomeSource5.",
					additional_assistance1=".$additionalAssistance1.",
					additional_assistance2=".$additionalAssistance2.",
					additional_assistance3=".$additionalAssistance3.",
					additional_assistance4=".$additionalAssistance4.",
					additional_assistance5=".$additionalAssistance5.",
					referred_to1=".$referredTo1.",
					referred_to2=".$referredTo2.",
					referred_from1=".$referredFrom1.",
					referred_from2=".$referredFrom2."
					WHERE consumer_id = ".$id;
} else {
	$query = "INSERT INTO intake1 (`id`, 
										`consumer_id`, 
										`voting`, 
										`date`, 
										`other_contact`, 
										`other_contact_phone`, 
										`other_language_needs`, 
										`other_other_language_needs`, 
										`living_arrangement_id`, 
										`age`, 
										`sex_id`, 
										`race_id`, 
										`marital_status_id`, 
										`dependents`, 
										`dependents_count`, 
										`birth_city`, 
										`birth_state_id`, 
										`citizen`, 
										`dob`, 
										`ethnicity`, 
										`primary_disability_id`, 
										`secondary_disability_id`, 
										`primary_disability_type_id`, 
										`secondary_disability_type_id`, 
										`congenital`, 
										`traumatic`, 
										`disease`, 
										`employee_signature`, 
										`eligibility_signoff`, 
										`consumer_signature`, 
										`services_DARS`, 
										`services_TCB`, 
										`services_MHMR`, 
										`services_DHS`, 
										`services_School`, 
										`services_SSA`, 
										`services_HAHA`, 
										`services_TAN`, 
										`services_Other`, 
										`counselor_name`, 
										`counselor_number`, 
										`income_Jobs`, 
										`income_SS`, 
										`income_SSI`, 
										`income_SSDI`, 
										`income_public_assistance`, 
										`income_clinic_card`, 
										`income_workmans_compensation`, 
										`income_pension`, 
										`income_medicare`, 
										`income_medicaid`, 
										`income_unemployment_benefits`, 
										`income_private_health_insurance`, 
										`transportation_option_id`, 
										`referral_name`, 
										`referral_other`, 
										`cap_signoff`, 
										`waiverILP`,
										`program_enrolled1`,
										`program_enrolled2`,
										`program_enrolled3`,
										`program_previous_enrolled1`,
										`program_previous_enrolled2`,
										`state_program_enrolled1`,
										`state_program_enrolled2`,
										`state_program_enrolled3`,
										`state_program_previous_enrolled1`,
										`state_program_previous_enrolled2`,
										`income_source1`,
										`income_source2`,
										`income_source3`,
										`income_source4`,
										`income_source5`,
										`additional_assistance1`,
										`additional_assistance2`,
										`additional_assistance3`,
										`additional_assistance4`,
										`additional_assistance5`,
										`referred_to1`,
										`referred_to2`,
										`referred_from1`,
										`referred_from2`) 
				VALUES ('NULL', 
						   ".$id.", 
						   ".$vote.", 
						   '".$date."', 
						   '".$otherName."', 
						   '".$otherPhone."', 
						   '".$otherLanguage."', 
						   '".$otherOtherLanguage."', 
						   ".$otherLiving.", 
						   ".$age.", 
						   ".$sex.", 
						   ".$race.", 
						   ".$maritalStatus.", 
						   ".$dependents.", 
						   ".$dependentsHowMany.", 
						   '".$birthplaceCity."', 
						   '".$birthplaceState."', 
						   ".$citizen.", 
						   '".$birthDate."',
						   '".$ethnicity."',
						   ".$primaryDisability.", 
						   '".$secondaryDisability."', 
						   ".$primaryDisabilityType.", 
						   '".$secondaryDisabilityType."', 
						   ".$congenital.", 
						   ".$traumatic.", 
						   ".$disease.", 
						   '".$employeeSignature."', 
						   ".$eligibilitySignoff.", 
						   '".$consumerSiganture."', 
						   ".$servicesDARS.",
						   ".$servicesTCB.",
						   ".$servicesMHMR.",
						   ".$servicesDHS.",
						   ".$servicesSchool.",
						   ".$servicesSSA.",
						   ".$servicesHAHA.",
						   ".$servicesTAN.",
						   ".$servicesOther.",
						   '".$counselorName."',
						   '".$counselorNumber."', 
						   ".$incomeJobs.",
						   ".$incomeSS.",
						   ".$incomeSSI.",
						   ".$incomeSSDI.",
						   ".$incomePublicAssistance.",
						   ".$incomeClinicCard.",
						   ".$incomeWorkmansCompensation.",
						   ".$incomePension.",
						   ".$incomeMedicare.",
						   ".$incomeMedicaid.",
						   ".$incomeUnemploymentBenefits.",
						   ".$incomePrivateHealthInsurance.",
						   ".$transportationOption.",
						   '".$referralName."',
						   '".$referralOther."',
						   ".$capSignoff.",
						   ".$waiverILP.",
						".$vailProgram1.",
						".$vailProgram2.",
						".$vailProgram3.",
						".$vailPreviousProgram1.",
						".$vailPreviousProgram2.",
						".$stateProgram1.",
						".$stateProgram2.",
						".$stateProgram3.",
						".$statePreviousProgram1.",
						".$statePreviousProgram2.",
						".$incomeSource1.",
						".$incomeSource2.",
						".$incomeSource3.",
						".$incomeSource4.",
						".$incomeSource5.",
						".$additionalAssistance1.",
						".$additionalAssistance2.",
						".$additionalAssistance3.",
						".$additionalAssistance4.",
						".$additionalAssistance5.",
						".$referredTo1.",
						".$referredTo2.",
						".$referredFrom1.",
						".$referredFrom2.");";
}

if(mysql_query($query)) {
  	//echo "Success <br/>".$query;
	header("Location:../admin.php?action=cieedit&id=".$id."&Status=Intake 1 Form Submitted Successfully");
	exit();
	//echo "Success <br/>".$query;
} else {
	echo "Failure <br/>".$query.mysql_error();
	header("Location:../admin.php?action=cieedit&id=".$id."&Error=Unable to process Intake 1 Form due to system error.  Please contact system administrator.");
	exit();
	//echo "Failure <br/>".$query;
}


